﻿<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:eim="clr-namespace:Microsoft.Expression.Interactivity.Media;assembly=Microsoft.Expression.Interactions" xmlns:ec="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions" xmlns:edc="clr-namespace:Microsoft.Expression.Controls;assembly=Microsoft.Expression.Drawing" xmlns:em="clr-namespace:Microsoft.Expression.Media;assembly=Microsoft.Expression.Drawing" xmlns:AllBots_Behaviour="clr-namespace:AllBots.Behaviour" x:Class="AllBots.View.SearchIdView"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    mc:Ignorable="d"
    d:DesignHeight="480" d:DesignWidth="480"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    DataContext="{Binding SearchId, Source={StaticResource Locator}}">
    
    <StackPanel x:Name="LayoutRoot">
    	<VisualStateManager.CustomVisualStateManager>
    		<ec:ExtendedVisualStateManager/>
    	</VisualStateManager.CustomVisualStateManager>
    	<i:Interaction.Behaviors>
    		<ec:DataStateBehavior Binding="{Binding IsSearching}" Value="True" TrueState="Searching" FalseState="Waiting"/>
    		<ec:DataStateBehavior Binding="{Binding Error}" TrueState="Valid" FalseState="Invalid"/>
    	</i:Interaction.Behaviors>
    	<VisualStateManager.VisualStateGroups>
    		<VisualStateGroup x:Name="SearchingStates">
    			<VisualState x:Name="Searching">
    				<Storyboard>
    					<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="progressBar">
    						<DiscreteObjectKeyFrame KeyTime="0">
    							<DiscreteObjectKeyFrame.Value>
    								<Visibility>Visible</Visibility>
    							</DiscreteObjectKeyFrame.Value>
    						</DiscreteObjectKeyFrame>
    					</ObjectAnimationUsingKeyFrames>
    				</Storyboard>
    			</VisualState>
    			<VisualState x:Name="Waiting">
    				<Storyboard>
    					<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="progressBar">
    						<DiscreteObjectKeyFrame KeyTime="0">
    							<DiscreteObjectKeyFrame.Value>
    								<Visibility>Collapsed</Visibility>
    							</DiscreteObjectKeyFrame.Value>
    						</DiscreteObjectKeyFrame>
    					</ObjectAnimationUsingKeyFrames>
    				</Storyboard>
    			</VisualState>
    		</VisualStateGroup>
    		<VisualStateGroup x:Name="ValidationStates" ec:ExtendedVisualStateManager.UseFluidLayout="True">
    			<VisualStateGroup.Transitions>
    				<VisualTransition GeneratedDuration="0:0:0.5"/>
    			</VisualStateGroup.Transitions>
    			<VisualState x:Name="Invalid">
    				<Storyboard>
    					<DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="callout" d:IsOptimized="True"/>
    					<ColorAnimation Duration="0" To="#BFFF0000" Storyboard.TargetProperty="(Control.BorderBrush).(SolidColorBrush.Color)" Storyboard.TargetName="textBox" d:IsOptimized="True"/>
    				</Storyboard>
    			</VisualState>
    			<VisualState x:Name="Valid">
    				<Storyboard>
    					<DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="callout" d:IsOptimized="True"/>
    				</Storyboard>
    			</VisualState>
    		</VisualStateGroup>
    	</VisualStateManager.VisualStateGroups>
    	<i:Interaction.Triggers>
    		<ec:DataTrigger Binding="{Binding FoundBotId}" Value="True">
    			<ec:NavigateToPageAction TargetPage="/ChatPage.xaml"/>
    		</ec:DataTrigger>
    	</i:Interaction.Triggers>
    	<edc:Callout x:Name="callout" AnchorPoint="0.09,1.42" CalloutStyle="Rectangle" Content="{Binding Error}" Fill="#BFFF0000" FontSize="{StaticResource PhoneFontSizeNormal}" HorizontalAlignment="Right" Height="66" Stroke="Black" Width="157" Canvas.ZIndex="1" StrokeThickness="3" Opacity="0" FontFamily="{StaticResource PhoneFontFamilySemiBold}" Margin="0,0,0,-27"/>
        <TextBlock TextWrapping="Wrap" Text="{Binding AppResources.GetByIdViewIdLabel, Source={StaticResource Localizator}}" FontFamily="{StaticResource PhoneFontFamilyNormal}" FontSize="{StaticResource PhoneFontSizeLarge}"/>
    	<TextBox x:Name="textBox" TextWrapping="Wrap" Text="{Binding SearchBot.Id, Mode=TwoWay, UpdateSourceTrigger=Explicit}">
    		<i:Interaction.Triggers>
    			<i:EventTrigger EventName="TextChanged">
    				<AllBots_Behaviour:UpdateBindingBehaviour/>
    			</i:EventTrigger>
    		</i:Interaction.Triggers>
    	</TextBox>
        <StackPanel Orientation="Horizontal">
            <TextBlock TextWrapping="Wrap" Text="{Binding AppResources.GetByIdViewNameLabel, Mode=OneWay, Source={StaticResource Localizator}, StringFormat=\{0\} :}" FontFamily="{StaticResource PhoneFontFamilyNormal}" FontSize="{StaticResource PhoneFontSizeLarge}"/>
            <TextBlock Text="{Binding SearchBot.Name}" Margin="8,0,0,0" FontSize="{StaticResource PhoneFontSizeLarge}" FontFamily="{StaticResource PhoneFontFamilyNormal}" />
        </StackPanel>
        <toolkit:ToggleSwitch Header="{Binding AppResources.SaveToLibrary, Source={StaticResource Localizator}}" Style="{StaticResource StandardToggleSwitchTemplate}" Margin="2,0,0,0" IsChecked="{Binding SaveToLibrary, Mode=TwoWay}" />
        <Button Content="{Binding AppResources.GetByIdViewGoButtonText, Source={StaticResource Localizator}}" Command="{Binding SearchCommand, Mode=OneWay}"/>
    	<ProgressBar x:Name="progressBar" Height="10" IsIndeterminate="True" Foreground="{StaticResource AccentBrush}"/>
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
            <TextBlock TextWrapping="Wrap" Text="{Binding AppResources.GoTo, Source={StaticResource Localizator}}" FontFamily="{StaticResource PhoneFontFamilyNormal}" FontSize="{StaticResource PhoneFontSizeNormal}" />
            <HyperlinkButton NavigateUri="http://www.pandorabots.com" Foreground="{StaticResource DarkBrush}" FontFamily="{StaticResource PhoneFontFamilySemiBold}" FontSize="{StaticResource PhoneFontSizeNormal}" TargetName="_blank" Cursor="Hand">http://www.pandorabots.com</HyperlinkButton>
        </StackPanel>
        <TextBlock Text="{Binding AppResources.ToCreateYourBot, Source={StaticResource Localizator}}" HorizontalAlignment="Center" FontFamily="{StaticResource PhoneFontFamilyNormal}" FontSize="{StaticResource PhoneFontSizeNormal}" />
    </StackPanel>
</UserControl>
